<template>
	<view>
		<view class="smart-page-head">
			<view class="smart-page-head-title">input 输入框</view>
		</view>
		<view class="smart-padding-wrap">
			<view class="item">可自动获取焦点的</view>
			<view>
				<input class="smart-input" focus="true" placeholder="自动获取焦点" />
			</view>

			<view class="item">右下角显示搜索</view>
			<view>
				<input class="smart-input" confirm-type="search" placeholder="右下角显示搜索" />
			</view>

			<view class="item">控制最大输入长度</view>
			<view>
				<input class="smart-input" maxlength="10" placeholder="控制最大输入长度为10" />
			</view>

			<view class="item">同步获取输入值</view>
			<view>
				<text style="color: #007AFF;">{{ inputValue }}</text>
				<input class="smart-input" @input="onKeyInput" placeholder="同步获取输入值" />
			</view>

			<view class="item">数字输入</view>
			<view>
				<input class="smart-input" type="number" placeholder="这是一个数字输入框" />
			</view>

			<view class="item">密码输入</view>
			<view>
				<input class="smart-input" type="text" password="true" placeholder="这是一个密码输入框" />
			</view>

			<view class="item">带小数点输入</view>
			<view>
				<input class="smart-input" type="digit" placeholder="这是一个带小数点输入框" />
			</view>

			<view class="item">身份证输入</view>
			<view>
				<input class="smart-input" type="idcard" placeholder="这是一个身份证输入框" />
			</view>

			<view class="item">带清除按钮</view>
			<view class="wrapper">
				<input class="smart-input" :value="clearInputValue" @input="clearInput" placeholder="这是一个带清除按钮输入框" />
				<text v-if="showClearIcon" class="uni-icon" @click="clearIcon">&#xe434;</text>
			</view>

			<view class="item">可查看密码的输入框</view>
			<view class="wrapper">
				<input class="smart-input" type="text" :password="!showPassword" placeholder="请输入密码" @input="onPasswordInput" />
				<text class="uni-icon" :class="{ 'eye-active': !showPassword }" @click="togglePasswordVisibility">&#xe568;</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inputValue: '',
				clearInputValue: '',
				showClearIcon: false,
				showPassword: false,
				passwordValue: ''
			};
		},
		methods: {
		
			onKeyInput(event) {
				this.inputValue = event.detail.value;
			},
		
			clearInput(event) {
				this.clearInputValue = event.detail.value;
				this.showClearIcon = event.detail.value.length > 0; 
			},
			clearIcon() {
				this.clearInputValue = '';
				this.showClearIcon = false;
			},
		
			onPasswordInput(event) {
				this.passwordValue = event.detail.value; 
			},
			togglePasswordVisibility() {
				this.showPassword = !this.showPassword; 
			}
		}
	};
</script>

<style>
.smart-page-head {
	background-color: white;
	padding: 15px;
	margin-bottom: 20rpx;
}
.smart-page-head-title {
	color: plum;
	font-size: 18px;
	font-weight: bold;
}
.smart-padding-wrap {
	padding: 15px;
}
.smart-input {
	width: 100%;
	height: 40px;
	line-height: 40px;
	padding: 0 10px;
	background-color: #f5f5f5;
	border-radius: 4px;
	margin-bottom: 20rpx;
	box-sizing: border-box;
}
.item {
	margin-bottom: 10rpx;
	font-size: 14px;
	color: #333;
}
.wrapper {
	display: flex;
	align-items: center; 
	background-color: #f5f5f5;
	border-radius: 4px;
	margin-bottom: 20rpx;
}
.wrapper .smart-input {
	margin-bottom: 0; 
	flex: 1;
	border: none;
}
.uni-icon {
	font-family: unicons;
	font-size: 24px;
	color: #999;
	padding: 0 10px;
	cursor: pointer;
}
.eye-active {
	color: #007aff; 
}
</style>